<?php
/*
  **
  **供应模块类文件
  **
 */

class getInfo_gy{

    /*
	  **获取供应分类，用于显示子分类,$class_id:传入的分类id，根据它列出子分类
	*/
	function getClass($class_id){
		return mysql_query("select * from gy_class where up=$class_id order by sort asc, id Desc");
	}


	function getinfo_list($school_id,$class,$ww,$page_size){
        $sql=mysql_query("select * from gy_class where up=$class");
	    $info=mysql_fetch_array($sql);
		
		//return mysql_query("select * from gylist where class_id=$info[id] order by time DESC limit $ww,$page_size");
        //return mysql_query("select user.*,gylist_2.*,school.*,gy_class.*,gylist.* from gylist JOIN  gylist_2  ON gylist_2.gy_id=gylist.id JOIN user ON gylist.user_id=user.id JOIN school ON gylist.school_id=school.id JOIN gy_class ON gylist.class_id=gy_class.up where gylist.school_id=$school_id and gylist.class_id=$class order by gylist.time DESC limit $ww,$page_size");	

		if($info==true){
		     return mysql_query("select user.*,gylist_2.*,school.*,gy_class.id,gy_class.up,gy_class.name as classname,gylist.* from gylist JOIN  gylist_2  ON gylist_2.gy_id=gylist.id JOIN user ON gylist.user_id=user.id LEFT JOIN school ON gylist.school_id=school.id JOIN gy_class ON gy_class.id=gylist.class_id where gylist.school_id=$school_id and gy_class.up=$class order by gylist.id DESC limit $ww,$page_size");
		}else{
		    return mysql_query("select user.*,gylist_2.*,school.*,gy_class.id,gy_class.up,gy_class.name as classname,gylist.* from gylist JOIN  gylist_2  ON gylist_2.gy_id=gylist.id JOIN user ON gylist.user_id=user.id LEFT JOIN school ON gylist.school_id=school.id INNER JOIN gy_class ON gylist.class_id=gy_class.id where gylist.school_id=$school_id and gylist.class_id=$class order by gylist.time DESC limit $ww,$page_size");
		}
	}

	function getinfo_detail($info_id){
		return mysql_query("select gylist.*,user.*,gylist_2.* from gylist JOIN  gylist_2  ON gylist_2.gy_id=gylist.id JOIN user ON gylist.user_id=user.id where  gylist.id=$info_id");
	}


	function class_query($class){
		return mysql_query("select * from gy_class where id='$class'");
	}

	function class_fetch($query){
		return mysql_fetch_array($query);
	}


    function gyAdd($title,$class,$xj,$price,$img,$content1,$school,$user,$qq,$tel,$time,$endtime){
		$checksql=mysql_query("select * from gylist where title='$title' and user_id='$user'");
		$checkinfo=$this->class_fetch($checksql);
		$nowtime=strtotime(date("Y-m-d h:i:s"));//当前时间
		$xg_time=$nowtime-$checkinfo[time];

		if($xg_time<3600){
           echo "<script language='javascript'>alert('您的信息已经提交成功了或者您在1小时内发布了同样的内容!');history.back();</script>";
		}else{
		     $info1=mysql_query("insert into gylist(school_id,class_id,user_id,title,xj,price,spic,time,endtime) values ('$school','$class','$user','$title','$xj','$price','$img','$time','$endtime')");
			

		     $id=mysql_insert_id();//获取插入的数据的id

		     $info2=mysql_query("insert into gylist_2(gy_id,content) values ('$id','$content1')");

			 if(!empty($qq)){
                 $user=mysql_query("update user set qq='$qq',tel='$tel' where id=$user");
			 }
		     if($info1==false||$info2==false||$user==false){
			     echo "<script language='javascript'>alert('信息发布失败，请重新发布!');history.back();</script>";
		     }

			 echo "<script language='javascript'>alert('您的信息发布成功喽!');history.back();</script>";
		}
 

	}


	function del($table,$id){
		$del=mysql_query("delete from $table where id=$id");
	}

	function gy_update($title,$xj,$price,$content,$qq,$tel,$openid,$id){
		$up1=mysql_query("update gylist set title='$title',xj='$xj',price='$price' where id='$id'");
		$up2=mysql_query("update gylist_2 set content='$content' where gy_id='$id'");
		$up3=mysql_query("update user set qq='$qq',tel='$tel' where openid='$openid'");

		if($up1==true&&$up2==true&&$up3==true){
			echo "<script>alert('编辑成功!');window.location.href='mygy_list.php';</script>";
		}

	}





}
?>